import { getCalendar, formDate } from '@/servers';
import { ref, reactive, watch } from 'vue';

const useCalendar = () => {
  const curDate = ref('');
  const state = reactive({
    date: {},
    holiday_array: []
    // holiday_list: []
  });
  watch(curDate, async () => {
    const [dateResponse, monthResponse] = await getCalendar(curDate.value);
    state.date = dateResponse;
    state.holiday_array = monthResponse.holiday_array;
    // state.holiday_list = yearResponse.holiday_list;
    // console.log(dateResponse, monthResponse, yearResponse);
  });

  const { inputDate } = formDate();
  curDate.value = inputDate;

  return {
    curDate,
    state
  };
};

export { useCalendar };
